package b3.widget.national
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.util.*;
	import b3.scene.home.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	
	import com.greensock.*;
	import com.greensock.easing.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.Point;
	import flash.text.*;

	public class NationalStarPane extends BasicWidget
	{
		private var starText:TextField;
		
		public function NationalStarPane()
		{
			super();
			var NationalStarPaneBgr:Class = ResourceHelper.getInstance().getClassByName("NationalStarPaneBgr");
			addChild(new NationalStarPaneBgr());
			starText = new TextField();
			starText.selectable = false;
        	starText.autoSize = TextFieldAutoSize.CENTER;
			starText.defaultTextFormat = new TextFormat(BFont.fontName, 13, 0xFF0000);
			starText.x = 50;
			starText.y = -2;
			addChild(starText);
			PlayerManager.getInstance().me.packageModel.addEventListener(ModelEvent.REFRESH, onRefresh);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			this.mouseChildren = false;
			onRefresh(null);
		}
		
		private function onRefresh(event:Event):void
		{
			var darkCoin:int = PlayerManager.getInstance().me.packageModel.getObjectNum(ObjConfig.NATIONAL_STAR);
			starText.text = " " + BFont.formatNumWithComa(darkCoin) + " ";
		}
			
		private function onMouseOver(event:MouseEvent):void
		{
			var container:Sprite = new Sprite();		
			//图标
			var GoldCoinIcon:Class = ResourceHelper.getInstance().getClassByName("NationalStarIcon");
			var goldCoinIcon:Sprite = new GoldCoinIcon();
			goldCoinIcon.height = 60;
			goldCoinIcon.scaleX = goldCoinIcon.scaleY;
			goldCoinIcon.x = 10;
			goldCoinIcon.y = 0;
			container.addChild(goldCoinIcon);
			//金币
			var me:Player = PlayerManager.getInstance().me;
			var goldCoinText:TextField = new TextField();
			goldCoinText.selectable = false;
			goldCoinText.autoSize = TextFieldAutoSize.LEFT;
			goldCoinText.defaultTextFormat = new TextFormat("微软雅黑", 25, 0xFFFFFF, true);
			goldCoinText.filters = [new GlowFilter(0xFF0000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			goldCoinText.text = "国庆五星，通过纪念碑收租获得";
			goldCoinText.x = 65;
			goldCoinText.y = 12;
			container.addChild(goldCoinText);
			HomeScene.getInstance().centerInfoPane.showInfo(container);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.clear();
		}
		
		//播放增加动画
		public function playAddMovie(startPos:Point, num:int):void
		{
			var targetPos:Point = this.localToGlobal(new Point(0, 0));
			HomeScene.getInstance().playCoinIncreaseMovie("NationalStarIcon", num, 0xFF0000, startPos, targetPos);
			TweenLite.delayedCall(2, onRefresh, [null]);
			BSound.getInstance().playEffect("SoundCoinPopout");
		}
		
	}
}